package mutithread.concurrent;

/**
 * 隋唐大舞台
 * Created by steve
 * 2018/10/17 2:00 PM
 */
public class StageThread extends Thread {

    @Override
    public void run() {

        ArmyRunnable armyRunnableDynasty = new ArmyRunnable();
        ArmyRunnable armyRunnableRevolt = new ArmyRunnable();

        Thread armySui = new Thread(armyRunnableDynasty, "隋军");
        Thread armyRevolt = new Thread(armyRunnableRevolt, "农民起义军");

        // 启动线程，开始作战
        armySui.start();
        armyRevolt.start();

        // 舞台线程休眠，军队嗜杀
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        KeyPersonThread mrCheng = new KeyPersonThread();
        mrCheng.setName("程咬金");


        // 停止作战
        armyRunnableDynasty.keepRunning = false;
        armyRunnableRevolt.keepRunning = false;

        System.out.println("程咬金登场");

        mrCheng.start();

        try {
            mrCheng.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("ok");
    }

    public static void main(String[] args) {
        StageThread stage = new StageThread();
        stage.start();
    }
}

